package com.javasm.adminapi.module.system.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.javasm.adminapi.common.R;
import com.javasm.adminapi.module.system.dto.RolePermissionDTO;
import com.javasm.adminapi.module.system.entity.Role;
import com.javasm.adminapi.module.system.service.RolePermissionService;
import com.javasm.adminapi.module.system.service.RoleService;
import com.javasm.adminapi.module.system.vo.RoleVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 角色表(Role)表控制层
 *
 * @author makejava
 * @since 2025-10-16 17:46:27
 */
@RestController
@RequestMapping("/role")
@Log4j2
public class RoleController {
    @Resource
    private RoleService roleService;

    @PostMapping("/page")
    public R page(@RequestBody RoleVo roleVo){
        PageInfo<Role> list = roleService.pageList(roleVo);
        return R.ok(list);
    }

    @PostMapping("/add")
    public R add(@RequestBody Role role){
        roleService.saveRole(role);
        return R.ok();
    }
    @PostMapping("/delete")
    public R delete(@RequestBody Integer id){
        List<Integer> ids = new ArrayList<>();
        ids.add(id);
        roleService.deleteByIds(ids);
        return R.ok();
    }

    @PostMapping("/batchDelete")
    public R deleteList(@RequestBody List<Integer> ids){
        roleService.deleteByIds(ids);
        return R.ok();
    }
    @PostMapping("/update")
    public R update(@RequestBody Role role){
        roleService.updateRole(role);
        return R.ok();
    }
    @Resource
    RolePermissionService rolePermissionService;

    @PostMapping("/updatemenu")
    public R updateMenu(@RequestBody RolePermissionDTO rolePermissionDTO){
        rolePermissionService.updateByRid(rolePermissionDTO);
        return R.ok();
    }

    @GetMapping("/all")
    public R all(){
        List<Role> list = roleService.list();
        return R.ok(list);
    }

}

